package net.lab1024.smartadmin.module.business.engineReverse.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.module.business.engineReverse.dao.EngineReverseDao;
import net.lab1024.smartadmin.module.business.engineReverse.domain.dto.EngineReverseAddDTO;
import net.lab1024.smartadmin.module.business.engineReverse.domain.dto.EngineReverseQueryDTO;
import net.lab1024.smartadmin.module.business.engineReverse.domain.dto.EngineReverseUpdateDTO;
import net.lab1024.smartadmin.module.business.engineReverse.domain.entity.EngineReverseEntity;
import net.lab1024.smartadmin.module.business.engineReverse.domain.vo.EngineReverseExcelVO;
import net.lab1024.smartadmin.module.business.engineReverse.domain.vo.EngineReverseVO;
import net.lab1024.smartadmin.util.SmartBeanUtil;
import net.lab1024.smartadmin.util.SmartPageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * [ 倒拖特性曲线 ]
 *
 * @author wuhq
 * @version 1.0
 * @company 倒拖特性曲线
 * @copyright (c)  倒拖特性曲线Inc. All rights reserved.
 * @date 2021-11-07 11:17:29
 * @since JDK1.8
 */
@Service
public class EngineReverseService {

    @Autowired
    private EngineReverseDao engineReverseDao;

    public EngineReverseEntity getByEngineId(Long id){
        LambdaQueryWrapper<EngineReverseEntity> queryWrapper = new LambdaQueryWrapper<EngineReverseEntity>();
        queryWrapper.eq(EngineReverseEntity::getEngineId, id);
        return engineReverseDao.selectOne(queryWrapper);
    }


    public void delByEngineId(Long engineId) {
        LambdaQueryWrapper<EngineReverseEntity> queryWrapper = new LambdaQueryWrapper<EngineReverseEntity>();
        queryWrapper.eq(EngineReverseEntity::getEngineId, engineId);
        engineReverseDao.delete(queryWrapper);

    }

    /**
     * 根据id查询
     */
    public EngineReverseEntity getById(Long id){
        return  engineReverseDao.selectById(id);
    }

    /**
     * 分页查询
     * @author wuhq
     * @date 2021-11-07 11:17:29
     */
    public ResponseDTO<PageResultDTO<EngineReverseVO>> queryByPage(EngineReverseQueryDTO queryDTO) {
        Page page = SmartPageUtil.convert2QueryPage(queryDTO);
        IPage<EngineReverseVO> voList = engineReverseDao.queryByPage(page, queryDTO);
        PageResultDTO<EngineReverseVO> pageResultDTO = SmartPageUtil.convert2PageResult(voList);
        return ResponseDTO.succData(pageResultDTO);
    }

    /**
     * 添加
     * @author wuhq
     * @date 2021-11-07 11:17:29
     */
    public ResponseDTO<String> add(EngineReverseAddDTO addDTO) {
        EngineReverseEntity entity = SmartBeanUtil.copy(addDTO, EngineReverseEntity.class);
        engineReverseDao.insert(entity);
        return ResponseDTO.succ();
    }

    /**
     * 编辑
     * @author wuhq
     * @date 2021-11-07 11:17:29
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> update(EngineReverseUpdateDTO updateDTO) {
        EngineReverseEntity entity = SmartBeanUtil.copy(updateDTO, EngineReverseEntity.class);
        engineReverseDao.updateById(entity);
        return ResponseDTO.succ();
    }

    /**
     * 删除
     * @author wuhq
     * @date 2021-11-07 11:17:29
     */
    @Transactional(rollbackFor = Exception.class)
    public ResponseDTO<String> deleteByIds(List<Long> idList) {
        engineReverseDao.deleteByIdList(idList);
        return ResponseDTO.succ();
    }

    /**
     * 查询全部导出对象
     * @author wuhq
     * @date 2021-11-07 11:17:29
     */
    public List<EngineReverseExcelVO> queryAllExportData(EngineReverseQueryDTO queryDTO) {
        return engineReverseDao.queryAllExportData( queryDTO);
    }

    /**
     * 批量查询导出对象
     * @author wuhq
     * @date 2021-11-07 11:17:29
     */
    public List<EngineReverseExcelVO> queryBatchExportData(List<Long> idList) {
        return engineReverseDao.queryBatchExportData(idList);
    }
}
